﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Services.Contracts.DTO.Infos;
using System.Data;
using Demo.CommonBase.Logging;
using System.Reflection;
using Demo.CommonBase.Exceptions;

namespace Demo.Services.Integration.DAO.IntegrationComponents.Mappings
{
    public class TecnologyDAOMapping
    {
        /// <summary>
        /// Obtener una Lista de Tecnologias
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static TecnologyResultInfo GetTecnologyList(DataSet ds)
        {
            TecnologyResultInfo result; 
            List<TecnologyInfo> tecnologyList;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                DataTable dt = ds.Tables[1];

                tecnologyList = (from tecnology in dt.AsEnumerable()
                          select new TecnologyInfo
                          {
                              Id = tecnology.Field<int>("Id"),
                              Description = tecnology.Field<string>("Nombre")
                          }).ToList();
                result = new TecnologyResultInfo();
                result.TecnologyList = tecnologyList;
                result.TotalReg = Convert.ToInt32(ds.Tables[0].Rows[0]["TotalReg"]);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }

        /// <summary>
        /// Obtener una tecnologia.
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static TecnologyInfo GetTecnologyById(DataSet ds)
        {
            TecnologyInfo result;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                DataTable dt = ds.Tables[0];

                result = (from tecnology in dt.AsEnumerable()
                          select new TecnologyInfo
                          {
                              Id = tecnology.Field<int>("id"),
                              Description = tecnology.Field<string>("Nombre")
                          }).ToList()[0];
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }

        /// <summary>
        /// Obtener una Lista de Tecnologias
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static List<TecnologyInfo> GetTecnologysByProyectMapping(DataSet ds)
        {
            List<TecnologyInfo> result;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                DataTable dt = ds.Tables[0];

                result = (from tecnology in dt.AsEnumerable()
                          select new TecnologyInfo
                          {
                              Id = tecnology.Field<int>("id"),
                              Description = tecnology.Field<string>("nombre")
                          }).ToList();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }
        public static List<TecnologyInfo> GetTecnologies(DataSet ds)
        {            
            List<TecnologyInfo> tecnologyList;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                DataTable dt = ds.Tables[0];

                tecnologyList = (from tecnology in dt.AsEnumerable()        
                                 select new TecnologyInfo               
                                 {
                                     Id = tecnology.Field<int>("Id"),                   
                                     Description = tecnology.Field<string>("Nombre")          
                                 }).ToList();                    
            }            catch (Exception ex)            {        
                Logger.Error(ex);             
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);      
            }            
            return tecnologyList;   
        }
        /// <summary>
        /// Obtener una Lista de Tecnologias
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static List<TecnologyInfo> GetTecnologysByResourceMapping(DataSet ds)
        {
            List<TecnologyInfo> result;
            try
            {
                Logger.Info();
                DataTable dt = ds.Tables[0];

                result = (from tecnology in dt.AsEnumerable()
                          select new TecnologyInfo
                          {
                              Id = tecnology.Field<int>("id"),
                              Description = tecnology.Field<string>("nombre")
                          }).ToList();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }

    }
}
